home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / edgetext / clserror.cl_ / clserror.cl
Encoding:
Visual Basic class definition  |  1998-03-30  |  4.0 KB  |  124 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. End
  5. Attribute VB_Name = "clsError"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. '********************************************************************************************************
  13. 'Title:     clsError
  14. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  15. 'Purpose    This class allows customizable Global Error trapping.  Errors may be displayed, or Logged or both
  16. '           Set the DisplayErrors Flag to True to display errors to users
  17. '           Set the LogErrors Flag to True and the LogFileName to the file name which will be
  18. '           used as the error log in order to log errors to the disk
  19. '
  20. 'It is recommended that the this class be declared global for persistence
  21. '**************************************************************************************
  22.  
  23. 'Function Where the Error Occurred
  24. Public FunctionName As String
  25.  
  26. 'Message is the message to display to the user when
  27. 'the display function is called, if it is blank, no
  28. 'message will be displayed
  29. Public Message As String
  30.  
  31. 'SQL is the SQL statement being executed at the
  32. 'time of the error
  33. Public SQL As String
  34.  
  35. 'ErrorCode should be set to the error code returned
  36. 'from the trap in which this class is called from
  37. Public ErrorCode as Double
  38.  
  39. 'This flag tells the class whether to display errors to the user or not
  40. Public DisplayErrors As Boolean
  41.  
  42. 'if LogErrors is false, no error log is created
  43. Public LogErrors As Boolean
  44.  
  45. 'LogFileName is the file which is being used to write an error log
  46. Public LogFileName As String
  47.  
  48. 'Success is the flag which is set to false if
  49. 'the display sub is unsuccessful
  50. Public Success as Boolean
  51.  
  52. '********************************************************************************************************
  53. 'Title:     Display
  54. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  55. 'Purpose    This sub displays a message to the user if the message string is filled
  56. '           an error log entry if the LogErrors flag is true
  57. 'Parameters:The Icon and or buttons to put on the msgbox
  58. 'Return:    Nothing
  59. '********************************************************************************************************
  60. Public Sub Display(piMsgBoxSuffix As Integer)
  61.  
  62.     If DisplayErrors Then
  63.         If ErrorCode = False Then
  64.             MsgBox Message, piMsgBoxSuffix
  65.         Else
  66.             MsgBox Message & " Error: " & Error(ErrorCode), piMsgBoxSuffix
  67.         End If
  68.     End If
  69.     
  70.     If LogErrors Then
  71.         Success = True
  72.         On Error GoTo DisplayError
  73.         Open LogFileName For Append As 1
  74.         If Not Success Then
  75.             Exit Sub
  76.         End If
  77.         Print #1, "-----------------------------------------------------------"
  78.         If Not Success Then
  79.             Close 1
  80.             Exit Sub
  81.         End If
  82.         Print #1, "Time:       " & Format(Now, "mm/dd/yyyy hh:mm:ss")
  83.         If Not Success Then
  84.             Close 1
  85.             Exit Sub
  86.         End If
  87.         If Trim(FunctionName) <> "" Then
  88.             Print #1, "Function:   " & FunctionName
  89.             If Not Success Then
  90.                 Close 1
  91.                 Exit Sub
  92.             End If
  93.         End If
  94.         If Trim(Message) <> "" Then
  95.             Print #1, "Message:    " & Message
  96.             If Not Success Then
  97.                 Close 1
  98.                 Exit Sub
  99.             End If
  100.         End If
  101.         If ErrorCode <> False Then
  102.             Print #1, "Error:      " & Error(ErrorCode)
  103.             If Not Success Then
  104.                 Close 1
  105.                 Exit Sub
  106.             End If
  107.         End If
  108.         If Trim(SQL) <> "" Then
  109.             Print #1, "SQL:        " & SQL
  110.             If Not Success Then
  111.                 Close 1
  112.                 Exit Sub
  113.             End If
  114.         End If
  115.         Close 1
  116.     End If
  117.     Exit Sub
  118.     
  119. DisplayError:
  120.     Success = False
  121.     Resume Next
  122.  
  123. End Sub
  124.